package logic

import (
	"context"
	"mall/mallrpc/mallrpc"

	"mall/api/internal/svc"
	"mall/api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type UserLikeLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewUserLikeLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UserLikeLogic {
	return &UserLikeLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *UserLikeLogic) UserLike(req *types.UserLikeRequest) (resp *types.Response, err error) {
	// todo: add your logic here and delete this line
	like, err := l.svcCtx.MallRpc.UserLike(l.ctx, &mallrpc.UserLikeRequest{ProductId: req.ProductId})
	if err != nil {
		return &types.Response{
			Message: err.Error(),
			Code:    "500",
			Data:    nil,
		}, nil
	}

	return &types.Response{
		Message: "收藏成功",
		Code:    "200",
		Data:    like,
	}, nil
}
